package com.learn.cloud.datascope.config;

import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import com.baomidou.dynamic.datasource.provider.DynamicDataSourceProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author MI
 */
@Component
public class DataSourceConfig {


    private final List<DynamicDataSourceProvider> providers;

    public DataSourceConfig(List<DynamicDataSourceProvider> providers) {
        this.providers = providers;
    }

    @Bean
    public DynamicRoutingDataSource dynamicRoutingDataSource() {
        // 在此处配置和构建你的 DynamicRoutingDataSource
        // 例如：
        DynamicRoutingDataSource dynamicRoutingDataSource = new DynamicRoutingDataSource(providers);
        // 配置你的数据源（添加目标数据源）
//         dynamicRoutingDataSource.addDataSource("dataSource1", dataSource1);
        // dynamicRoutingDataSource.addDataSource("dataSource2", dataSource2);
        // ...

        return dynamicRoutingDataSource;
    }
}
